<?php
include($folder.'/layouts/code-behind/backend.php');
function blc_gyerekszaj_select($from, $itemsPerPage, $sortColumn, $sortDirection)
{
	$orderBy = $sortColumn.'_'.$sortDirection;
	$data = query(
		'SELECT 
			gy.id AS id, 
			gy.content AS aContent, 
			DATE_FORMAT(gy.created,\'%Y.%m.%d. %H:%i\') AS aCreated 
		FROM gyerekszaj gy
		ORDER BY 
			CASE WHEN :orderBy = \'content_asc\' THEN aContent END ASC,
			CASE WHEN :orderBy = \'content_desc\' THEN aContent END DESC,
			CASE WHEN :orderBy = \'created_asc\' THEN aCreated END ASC,
			CASE WHEN :orderBy = \'created_desc\' THEN aCreated END DESC
		LIMIT :from,:itemsPerPage', array('orderBy'=>$orderBy,'from'=>$from,'itemsPerPage'=>$itemsPerPage));
	foreach ($data as &$item)
	{
		$item['aContent'] = substr($item['aContent'], 0, 70).' ...';
	}
	return $data;
}
function blc_gyerekszaj_select_count()
{
	return queryScalar('SELECT COUNT(1) FROM gyerekszaj', null);
}
?>